<template>
  <div class="person">
    <h2>情况三：监视reactive定义的【对象类型】数据:且默认开启了深度监视。</h2>
    <h2>姓名：{{ person.name }}</h2>
    <h2>姓名：{{ person.age }}</h2>
    <button @click="handleName">修改姓名</button>
    <button @click="handleAge">修改年龄</button>
    <button @click="handlePer">修改整个人</button>
  </div>
</template>
  <script setup lang='ts'>
import { reactive, watch } from "vue";
let person = reactive({
  name: "张三",
  age: 18
});
function handleName() {
  person.name += "~";
}
function handleAge() {
  person.age += 1;
}
function handlePer() {
  // person = Object.assign(person,{name:"历史",age:123});
  //或者
  Object.assign(person, { name: "历史", age: 123 });
}
//watch("监听谁",回调函数,"深度监听")
//监视reactive定义的【对象类型】数据:且默认开启了深度监视。
watch(person, (newV, oldV) => {
  console.log("person变化了", newV, oldV);
});
</script>
  <style scoped>
.person {
  background-color: skyblue;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
</style>